import { verifyAccessToken } from '~/utils/jwt-utils';
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';

export default eventHandler(async (event) => {
  const userinfo = verifyAccessToken(event);
  if (!userinfo) {
    return unAuthorizedResponse(event);
  }

  const body = await readBody(event);
  const id = getRouterParam(event, 'id');

  // 模拟更新客户
  const updatedCustomer = {
    id,
    ...body,
    updateTime: new Date().toLocaleString('zh-CN'),
  };

  return useResponseSuccess(updatedCustomer);
});